﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MagicalFX;

public class FireRockController : MonoBehaviour
{
    public GameObject fire_Rock;
    private Transform originPos;
    Vector3 position;
    public  List<GameObject> RockList;
    public static FireRockController Instance;


    /// <summary>
    /// 岩石实例化位置
    /// </summary>
    public Transform OriginPos
    {
        get
        {
            originPos = GameObject.Find("RockInstantiatePos").transform;
            return originPos;
        }
        set
        {
            originPos = value;
        }
    }

    void Awake()
    {
        Instance = this;
        Vector2 p1 = Random.insideUnitCircle * 20;
        Vector2 p2 = p1.normalized * (10 + p1.magnitude);
        //空心圆随机位置
        Vector3 position = OriginPos.position + new Vector3(p2.x, 10, p2.y);
        position = Vector3.zero;
        //VuforiaManager.Instance.ARCameraTransform.GetComponentInChildren<Camera>()
        RockList = new List<GameObject>();
    }


    public void OnFireRockButtonClick()
    {
        //Test Start~
        position = OriginPos.position;
        if (RockList.Count<3)
        {
            StartCoroutine(Spawn(position));
            Debug.Log(RockList.Count);
        }
       
    }


    /// <summary>
    /// 实例化岩石
    /// </summary>
    public IEnumerator Spawn(Vector3 position)
    {
        //fire_Rock = SpawnerObjectPool.instance.OutPool("Fire_Rock");
        GameObject rock = Instantiate(fire_Rock, position, Quaternion.identity);
        RockList.Add(fire_Rock);
        rock.transform.position = position;
        rock.transform.SetParent(OriginPos);
        yield return new WaitForSeconds(3f);
        RockList.Remove(fire_Rock);
    }

}
